﻿@{
    ViewBag.Title = "TruckIndex";
}


<div style="width: 100%;">
    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <a id="add" class="mini-button" iconcls="icon-node" plain="true" onclick="SingIn()">签收入库</a>
                    <a id="add" class="mini-button" iconcls="icon-node" plain="true" onclick="AddBroken()">缺货损坏记录</a>
                </td>
                <td style="white-space: nowrap;">
                     发货地<input id="StartCity" class="mini-textbox"  style="width: 100px;" onenter="onKeyEnter" />
                    收货地<input id="EndCity" class="mini-textbox"  style="width: 100px;" onenter="onKeyEnter" />
                    货物编号<input id="key" class="mini-textbox" emptytext="" style="width: 100px;" onenter="onKeyEnter" />
                    <a class="mini-button" plain="true" onclick="search()">查询</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="mini-fit" style="height: 100%;">
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;"
        url="GetTruckList"  pagesize="20"
        allowcelledit="true" allowcellselect="true" multiselect="true"
        editnextonenterkey="true" editnextrowcell="true">
        <div property="columns">
            <div type="indexcolumn"></div>
            <div type="checkcolumn" ></div>
             <div field="TruckNum"  headeralign="center" >
                车牌号
            </div>
            <div field="DriverName"  headeralign="center" >
                司机姓名
            </div>
             <div field="DriverTel"  headeralign="center" >
                联系电话
            </div>
            <div field="LoadDate"  headeralign="center" >
                起运时间
            </div>
            <div field="StatusName" headeralign="center" >
                状态
            </div>
             <div name="Details" width="40" allowsort="true">详细</div>
        </div>
    </div>
</div>


<script type="text/javascript">

    mini.parse();

    var grid = mini.get("datagrid1");
    grid.load({
        fail: function () {
        }
    });

    function search() {
        var key = mini.get("key").getValue();
        var StartCity = mini.get("StartCity").getValue();
        var EndCity = mini.get("EndCity").getValue();

        grid.load({
            key: key, StartCity: StartCity, EndCity: EndCity, fail: function () {
            }
        });
    }

    function onKeyEnter(e) {
        search();
    }
    grid.on("drawcell", function (e) {
        var record = e.record,
            column = e.column,
            field = e.field,
            value = e.value;
        if (column.name == "Details") {
            e.cellStyle = "text-align:left";
            e.cellHtml = "<a href=\"javascript:OpenOrderDetail('" + record.TruckID + "')\">详细</a>";
        }
    }
    );


    function SingIn() {
        grid.validate();
        if (grid.isValid() == false) {
            var error = grid.getCellErrors()[0];
            grid.beginEditCell(error.record, error.column);
            return;
        }

        var rows = grid.getSelecteds();
        if (rows.length != 1) {
            alert("请选择一条数据！");
            return;
        }

        var TruckID = rows[0].TruckID;

        //grid.loading("保存中，请稍后......");
        $.ajax({
            url: "SingIn",
            data: { TruckID: TruckID },
            type: "post",
            success: function (text, flag, res) {
                grid.unmask();
                if (res.responseText == "") {
                    grid.reload();
                }
                else {
                    grid.reload();
                    top.mini.alert(res.responseText);
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                mini.alert(errorThrown.responseText);
            }
        });
    }


    function AddBroken() {
        
        grid.validate();
        if (grid.isValid() == false) {
            var error = grid.getCellErrors()[0];
            grid.beginEditCell(error.record, error.column);
            return;
        }

        var rows = grid.getSelecteds();
        if (rows.length != 1) {
            alert("请选择一条数据！");
            return;
        }
        var TruckID = rows[0].TruckID;
        var win = mini.open({
            url: "/BusinessData/Arrived/AddDamage?TruckID=" + TruckID,
            title: "添加丢失破损", width: screen.width * 0.9, height: screen.height * 0.7,
            iconCls: "icon-createNews",
            showMaxButton: true,
            onload: function () {
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }

    function OpenOrderDetail(TruckID) {
        var win = mini.open({
            url: "/BusinessData/Arrived/TruckOrderDetail?TruckID=" + TruckID,
            title: "详细", width: screen.width * 0.9, height: screen.height * 0.7,
            iconCls: "icon-createNews",
            showMaxButton: true,
            onload: function () {
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
        //win.max();
    }

</script>


